Skip to content

fix(factory): handle EAGAIN/EBADF from stdin in non-blocking environments - #318

Merged
JoshMock merged 2 commits into
mainfrom
fix/stdin-eagain-crash
Jul 24, 2026
Merged

fix(factory): handle EAGAIN/EBADF from stdin in non-blocking environments#318
JoshMock merged 2 commits into
mainfrom
fix/stdin-eagain-crash

Conversation

@margaretjgu

Copy link
Copy Markdown
Member

Summary

Fixes #311.

In IDE terminals (Cursor, VS Code integrated terminal) and some CI environments, process.stdin.isTTY is falsy even when no data is piped. Attempting a synchronous readFileSync(0) in those conditions fails with EAGAIN (non-blocking fd, no data ready) or EBADF, which produced an unhandled exception with a raw Node.js stack trace on any command with an input schema (the entire es namespace).

Changes

  • src/factory.ts: wrap the stdinReader() call site with a try-catch that converts EAGAIN / EBADF to empty string, consistent with the existing empty-string path. All other errors are re-thrown unchanged.
  • test/factory.test.ts: three new tests covering EAGAIN, EBADF, and re-throw of unexpected errors.

Test plan

  • treats EAGAIN from stdin as no input -- new
  • treats EBADF from stdin as no input -- new
  • re-throws unexpected stdin errors (not EAGAIN/EBADF) -- new
  • All 266 existing factory tests still pass

@github-actions

github-actions Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 0.95s
✅ REPOSITORY gitleaks yes no no 60.21s
✅ REPOSITORY git_diff yes no no 0.72s
✅ REPOSITORY secretlint yes no no 30.28s
✅ REPOSITORY trivy yes no no 19.3s
✅ TYPESCRIPT eslint 2 0 0 4.96s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@margaretjgu
margaretjgu marked this pull request as draft May 14, 2026 00:31
…ents

In IDE terminals (Cursor, VS Code integrated terminal) and some CI
environments, process.stdin.isTTY is falsy even when no data is piped.
Attempting a synchronous readFileSync(0) in those conditions fails with
EAGAIN (non-blocking fd, no data ready) or EBADF, producing an unhandled
exception with a raw Node.js stack trace.

Catch EAGAIN and EBADF at the stdinReader call site and treat them as
empty input, consistent with the existing empty-string path. All other
errors are re-thrown unchanged.

Fixes #311
@margaretjgu
margaretjgu force-pushed the fix/stdin-eagain-crash branch from dd83314 to 9324f5d Compare July 22, 2026 20:05
@margaretjgu
margaretjgu marked this pull request as ready for review July 22, 2026 20:11
@JoshMock
JoshMock merged commit 14a22ef into main Jul 24, 2026
28 checks passed
@JoshMock
JoshMock deleted the fix/stdin-eagain-crash branch July 24, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(factory): EAGAIN crash when stdin is non-blocking but empty

2 participants